﻿namespace GreenIsomer.Data.Entities.Ddl {
	using System;
	using System.Xml.Serialization;

	[Serializable]
	public class ProviderSettings {

		[NonSerialized]
		private TypeConversionCollection typeConversions;

		public ProviderSettings() {
			typeConversions = new TypeConversionCollection();
		}

		[XmlAttribute("Provider")]
		public string Provider { get; set; }

		[XmlAttribute("BooleanLiteral")]
		public ProviderBooleanLiteral BooleanLiteral { get; set; }

		[XmlAttribute("StringEscape")]
		public ProviderStringEscape StringEscape { get; set; }

		[XmlAttribute("StringLiteralPrefix")]
		public string StringLiteralPrefix { get; set; }

		[XmlAttribute("GuidFormat")]
		public ProviderGuidFormat GuidFormat { get; set; }

		[XmlElement("GuidFunction")]
		public FunctionRef GuidFunction { get; set; }

		[XmlElement("DateTimeFormat")]
		public string DateTimeFormat { get; set; }

		[XmlElement("TypeConversion")]
		public TypeConversionCollection TypeConversions {
			get { return typeConversions; }
		}

		public bool ShouldSerializeBooleanLiteral() { 
			return BooleanLiteral != ProviderBooleanLiteral.Numeric; 
		}

		public bool ShouldSerializeStringEscape() {
			return StringEscape != ProviderStringEscape.TwoSingleQuotes;
		}

		public bool ShouldSerializeGuidFormat() {
			return GuidFormat != ProviderGuidFormat.StringWithoutBraces;
		}

		public bool ShouldSerializeGuidFunction() {
			if(GuidFunction == null) return false;
			if(!string.IsNullOrEmpty(GuidFunction.Schema)) return true;
			return GuidFunction.Name != "setguid";
		}

	}

}